home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / LANG / C / GCC / CLIB / !clib / h / fcntl < prev    next >
Text File  |  1997-04-06  |  6KB  |  205 lines

  1. /****************************************************************************
  2.  *
  3.  * $Source: /unixb/home/unixlib/source/unixlib37/clib/h/RCS/fcntl,v $
  4.  * $Date: 1996/10/30 21:58:58 $
  5.  * $Revision: 1.3 $
  6.  * $State: Exp $
  7.  * $Author: unixlib $
  8.  *
  9.  * $Log: fcntl,v $
  10.  * Revision 1.3  1996/10/30 21:58:58  unixlib
  11.  * Massive changes made by Nick Burret and Peter Burwood.
  12.  *
  13.  * Revision 1.2  1996/07/21 22:15:12  unixlib
  14.  * CL_0001 Nick Burret
  15.  * Improve memory handling. Remove C++ library incompatibilities.
  16.  * Improve file stat routines.
  17.  *
  18.  * Revision 1.1  1996/04/19 21:02:57  simon
  19.  * Initial revision
  20.  *
  21.  ***************************************************************************/
  22.  
  23. /* POSIX Standard 6.5: File Control Operations <fcntl.h> */
  24.  
  25. #ifndef __FCNTL_H
  26. #define __FCNTL_H
  27.  
  28. #ifndef __LIBC_TYPES_H
  29. #include <libc/types.h>
  30. #endif
  31.  
  32. #ifdef __cplusplus
  33. extern "C" {
  34. #endif
  35.  
  36. /* These fcntlbits are derived from 4.4 BSD.  */
  37.  
  38. #define O_OMASK     3
  39.  
  40. /* File access modes for open and fcntl.  */
  41.  
  42. /* Open for read only.  */
  43. #define O_RDONLY    0
  44. /* Open for write only.  */
  45. #define O_WRONLY    1
  46. /* Open for read/write.  */
  47. #define O_RDWR        2
  48.  
  49. /* Bits OR'd into the second argument to open.  */
  50.  
  51. /* Create file if it doesn't exist.  */
  52. #define O_CREAT     0x0200
  53. /* Fail if file already exists.  */
  54. #define O_EXCL        0x0800
  55. /* Truncate file to zero length.  */
  56. #define O_TRUNC            0x0400
  57. /* Send SIGIO to owner when data is ready.  */
  58. #define O_ASYNC        0x0040
  59. /* Synchronous writes.  */
  60. #define O_FSYNC        0x0080
  61. #define O_SYNC        O_FSYNC
  62. /* Open with shared file lock.  */
  63. #define O_SHLOCK    0x0010
  64. /* Open with shared exclusive lock.  */
  65. #define O_EXLOCK    0x0020
  66.  
  67. /* File status flags for open and fcntl.  */
  68.  
  69. /* Writes append to the file.  */
  70. #define O_APPEND    0x0008
  71. /* Non-blocking I/O.  */
  72. #define O_NONBLOCK      0x0004
  73. #define O_NDELAY    O_NONBLOCK
  74.  
  75. /* close on exec() flag - must be bit 8 */
  76. #define O_EXECCL    0x0100
  77.  
  78. #define O_BINARY    0x2000
  79. #define O_TEXT        0x1000
  80.  
  81. #define O_PIPE        0x4000 /* UnixLib specific */
  82.  
  83. /* Mask for file access modes.  This is system-dependent in case
  84.    some system ever wants to define some other flavor of access.  */
  85. #define    O_ACCMODE    (O_RDONLY|O_WRONLY|O_RDWR)
  86.  
  87.  
  88. /* Duplicate file descriptor.  */
  89. #define F_DUPFD     0
  90. /* Return file descriptor flags.  */
  91. #define F_GETFD     1
  92. /* Set file descriptor flags.  */
  93. #define F_SETFD     2
  94. /* Read file status flags.  */
  95. #define F_GETFL     3
  96. /* Set file status flags.  */
  97. #define F_SETFL     4
  98. /* Get owner (receiver of SIGIO).  */
  99. #define F_GETOWN        5
  100. /* Set owner (receiver of SIGIO).  */
  101. #define F_SETOWN        6
  102. /* Get record locking info.  */
  103. #define F_GETLK            7
  104. /* Set record locking info (non-blocking).  */
  105. #define F_SETLK        8
  106. /* Set record locking info (blocking).  */
  107. #define F_SETLKW    9
  108.  
  109. /* Bits in the file status flags returned by F_GETFL.  */
  110. #define FREAD        1
  111. #define    FWRITE        2
  112.  
  113. /* Traditional BSD names the O_* bits.  */
  114. #define FASYNC        O_ASYNC
  115. #define FCREAT        O_CREAT
  116. #define FEXCL        O_EXCL
  117. #define FTRUNC        O_TRUNC
  118. #define FNOCTTY        O_NOCTTY
  119. #define FFSYNC        O_FSYNC
  120. #define FSYNC        O_SYNC
  121. #define FAPPEND        O_APPEND
  122. #define FNONBLOCK    O_NONBLOCK
  123. #define FNDELAY        O_NDELAY
  124.  
  125.  
  126. /* If set, cause the file descriptor to be closed if an exec function
  127.    is used.  Initially, set clear.  */
  128. #define FD_CLOEXEC    O_EXECCL
  129.  
  130. /* The structure describing an advisory lock.  This is the type of the third
  131.    argument to `fcntl' for the F_GETLK, F_SETLK, and F_SETLKW requests.  */
  132. struct flock
  133.   {
  134.     /* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK.  */
  135.     short int l_type;
  136.     /* Where `l_start' is relative to (like `lseek').  */
  137.     short int l_whence;
  138.     /* Offset where the lock begins.  */
  139.     __off_t l_start;
  140.     /* Size of the locked area; zero means until EOF.  */
  141.     __off_t l_len;
  142.     /* Process holding the lock.  */
  143.     short int l_pid;
  144.   };
  145.  
  146. /* Values for the `l_type' field of a `struct flock'.  */
  147. #define    F_RDLCK    1    /* Read lock.  */
  148. #define    F_WRLCK    2    /* Write lock.  */
  149. #define    F_UNLCK    3    /* Remove lock.  */
  150.  
  151.  
  152. #ifndef    R_OK
  153. /* Straight from <unistd.h>.  */
  154.  
  155. /* Values for the second argument to access.
  156.    These may be OR'd together.  */
  157.  
  158. /* Test for read permission.  */
  159. #define    R_OK    4
  160. /* Test for write permission.  */
  161. #define    W_OK    2
  162. /* Test for execute permission.  */
  163. #define    X_OK    1
  164. /* Test for existence.  */
  165. #define    F_OK    0
  166. #endif
  167.  
  168.  
  169. /* Do the file control operation described by CMD on FD.
  170.    The remaining arguments are interpreted depending on CMD.  */
  171. extern int fcntl (int fd, int cmd, ...);
  172.  
  173. /* Open FILE and return a new file descriptor for it, or -1 on error.
  174.    OFLAG determines the type of access used.  If O_CREAT is on OFLAG,
  175.    the third argument is taken as a `mode_t', the mode of the created file.  */
  176. extern int open (const char *file, int oflag, ...);
  177.  
  178. /* Create and open FILE, with mode MODE.
  179.    This takes an `int' MODE argument because that is
  180.    what `mode_t' will be widened to.  */
  181. extern int creat (const char *file, __mode_t mode);
  182.  
  183. #ifndef F_LOCK
  184. /* These declarations also appear in <unistd.h>; be sure to keep both
  185.    files consistent.  */
  186.  
  187. /* `lockf' is a simpler interface to the locking facilities of `fcntl'.
  188.    LEN is always relative to the current file position.
  189.    The CMD argument is one of the following.  */
  190.  
  191. #define F_ULOCK 0       /* Unlock a previously locked region.  */
  192. #define F_LOCK  1       /* Lock a region for exclusive use.  */
  193. #define F_TLOCK 2       /* Test and lock a region for exclusive use.  */
  194. #define F_TEST  3       /* Test a region for other processes locks.  */
  195.  
  196. extern int lockf (int fd, int cmd, __off_t len);
  197. #endif
  198.  
  199.  
  200. #ifdef __cplusplus
  201.     }
  202. #endif
  203.  
  204. #endif
  205.